﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using System.Collections.Generic;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.CommonPage
{
    public partial class HospitalInfo : BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Header.Title = "医疗机构信息查看";
            //绑定医疗机构基本信息
            if (!IsPostBack)
            {
                string hospitalId = Request.QueryString["hospitalId"];
                IBLL_Hospital ih = Factory.BLL_Hospital();
                Model.HospitalInfo hospital = ih.GetHospitalInfoByID(hospitalId);
                if (hospital != null)
                {
                    lblHospitalName.Text = hospital.HospitalName;
                    lblAddress.Text = hospital.Address;
                    lblLevel.Text = hospital.Levels;
                    lblArea.Text = GetFullAreaName(hospital.AreaID);
                    lblContactPerson.Text = hospital.ContactPerson;
                    lblTell.Text = hospital.TelNo;
                    lblMobile.Text = hospital.CellNo;
                    lblEmail.Text = hospital.Email;

                    IBLL_User iu = Factory.BLL_User();
                    int TotalCount = 0;
                    IList<HZ.DrugTrade.Model.View.OrgUsers> listUser = iu.GetOrgUsersByWhere(new Model.Query.OrgUsers() { RoleID = "01", OrgID = hospitalId, SortFields = " LastLoginTime DESC" }, 1, 0, out TotalCount);
                    //置空用户IDs字符串
                    if (listUser.Count > 0)
                    {
                        HZ.DrugTrade.Model.View.OrgUsers user = listUser[0];
                        lblLastlogin.Text = user.LastLoginTime.HasValue ? user.LastLoginTime.Value.ToString("yyyy-MM-dd") : "<font color=red>从未登录过</font>";
                    }
                    else
                    {
                        lblLastlogin.Text = "<font color=red>从未登录过</font>";
                    }
                }
                else
                {
                    PageError("医疗机构不存在！", "");
                }
            }

        }

        /// <summary>
        /// 获取地区全路径
        /// </summary>
        /// <param name="areaId"></param>
        /// <returns></returns>
        private string GetFullAreaName(string areaId)
        {
            string fullAreaName = "";
            IBLL_Area areaCtrl = Factory.BLL_Area();

            Area area = areaCtrl.GetArea(areaId);
            fullAreaName = area.AreaName;
            if (area.FatherAreaID != "0")
            {
                Area father = areaCtrl.GetArea(area.FatherAreaID);
                fullAreaName = father.AreaName + ">>" + fullAreaName;


                if (father.FatherAreaID != "0")
                {
                    Area father2 = areaCtrl.GetArea(area.FatherAreaID);
                    fullAreaName = father2.AreaName + ">>" + fullAreaName;
                }
            }
            return fullAreaName;
        }
    }
}
